<template>
  <div style="height:100%">
    <el-container style="height:100%">
      <!-- 头部 -->
      <el-header>
        <el-row>
          <el-col :span="11">
            头部LOGO区
          </el-col>
          <el-col :span="11">
            <h2>电商后台管理系统</h2>
          </el-col>
          <el-col :span="2">
            <el-button
              type="danger"
              @click="Out"
            >退出登录</el-button>
          </el-col>
        </el-row>
      </el-header>
      <el-container>
        <!-- 左侧栏 -->
        <el-aside :width="isCollapse?'60px':'200px'">
          <div
            class="ssk"
            @click="isCollapse=!isCollapse"
          >
            <i class="el-icon-s-unfold"></i>
          </div>
          <!-- 导航 -->
          <el-menu
            :default-active="$route.path"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :collapse="isCollapse"
            :collapse-transition="false"
            :unique-opened="true"
            :router="true"
          >

            <el-submenu
              :index="item.id+''"
              v-for="item in menus"
              :key="item.id"
            >
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{item.authName}}</span>
              </template>
              <el-menu-item-group
                v-for="itm in item.children"
                :key="itm.id"
              >

                <el-menu-item :index="'/'+itm.path">
                  <i class="el-icon-location"></i>
                  {{itm.authName}}
                </el-menu-item>
              </el-menu-item-group>
            </el-submenu>

          </el-menu>
          <!-- 导航 -->
        </el-aside>
        <!-- 中间 -->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>

  </div>
</template>

<script>
import { DaoHang } from "@/http/api";
export default {
  data() {
    return {
      isCollapse: false,
      menus: []
    };
  },
  created() {
    this.xr();
  },
  methods: {
    Out() {
      sessionStorage.removeItem("token");
      sessionStorage.removeItem("ind");
      this.$router.replace("/login");
    },
    async xr() {
      let res = await DaoHang();
      this.menus = res;
      console.log("左侧菜单", this.menus);
    }
  }
};
</script>

<style scoped lang="scss">
.el-header {
  background: #333744;
  color: white;

  .el-row {
    display: flex;
    align-items: center;
    height: 100%;
  }
}
.el-aside {
  background: #333744;
  color: white;
}
.ssk {
  width: 100%;
  text-align: center;
  height: 30px;
  line-height: 30px;
  font-size: 20px;
}
.el-main {
  height: 875px;
}
</style>
